package com.example.demo.controller;

import com.example.demo.entity.Goods;
import com.example.demo.entity.ResponseResult;
import com.example.demo.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/goods")
@Api(tags = "商品接口")
public class GoodsController {

    @Autowired
    @Lazy(value = true)
    private GoodsService goodsService;


    @GetMapping
    @ApiOperation(value = "查询全部商品信息")
    public ResponseResult getList(){
        return goodsService.getList();
    }

    @GetMapping("/byName/{name}")
    @ApiOperation(value = "根据商品名字查询")
    public ResponseResult getByName(@PathParam(value = "name")String name){
        return goodsService.getByName(name);
    }

    @PostMapping
    @ApiOperation(value = "新增商品信息")
    public ResponseResult saveGoods(@RequestBody Goods goods){
        return goodsService.savaGoods(goods);
    }

    @PutMapping
    @ApiOperation(value = "修改商品信息")
    public ResponseResult updateGoods(@RequestBody Goods goods){
        return goodsService.updateGoods(goods);
    }

    @DeleteMapping("/deleteById")
    @ApiOperation(value = "根据id删除商品信息")
    public ResponseResult deleteById(@RequestParam String id){
        return  goodsService.deleteById(id);
    }

    @DeleteMapping("deleteByName")
    @ApiOperation(value = "根据商品名称删除")
    public ResponseResult deleteByName(@RequestParam String name){
        return goodsService.deleteByName(name);
    }
}
